]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
app-system: Lazily create ShellApps for apps we care about
authorJasper St. Pierre <jstpierre@mecheye.net>
Thu, 26 Sep 2013 21:06:47 +0000 (17:06 -0400)
committerJasper St. Pierre <jstpierre@mecheye.net>
Sun, 3 Nov 2013 00:50:35 +0000 (20:50 -0400)
Rather than create all ShellApps up-front, create them lazily. We really
had no reason to do this before as we were scanning GMenu to get all the
apps, but doing this can remove a need for get_all, which is slow and
memory-hungry.

src/shell-app-system.c

index 7b38fe513c5d3b8e16d9220bf10b3c24d1fc93e3..d9e39e912701a1c7fcd2acb91ef12a8edd5e7ae0 100644 (file)
@@ -71,26 +71,6 @@ static void shell_app_system_class_init(ShellAppSystemClass *klass)
   g_type_class_add_private (gobject_class, sizeof (ShellAppSystemPrivate));
 }
 
-static void
-load_apps (ShellAppSystem *self)
-{
-  ShellAppSystemPrivate *priv = self->priv;
-  GList *apps, *l;
-
-  apps = g_app_info_get_all ();
-  for (l = apps; l != NULL; l = l->next)
-    {
-      GAppInfo *info = l->data;
-      g_hash_table_insert (priv->id_to_app,
-                           (char *) g_app_info_get_id (info),
-                           _shell_app_new (G_DESKTOP_APP_INFO (info)));
-    }
-
-  g_list_free_full (apps, g_object_unref);
-
-  g_signal_emit (self, signals[INSTALLED_CHANGED], 0);
-}
-
 static void
 shell_app_system_init (ShellAppSystem *self)
 {
@@ -106,8 +86,6 @@ shell_app_system_init (ShellAppSystem *self)
                                            (GDestroyNotify)g_object_unref);
 
   priv->startup_wm_class_to_id = g_hash_table_new (g_str_hash, g_str_equal);
-
-  load_apps (self);
 }
 
 static void
@@ -150,7 +128,21 @@ ShellApp *
 shell_app_system_lookup_app (ShellAppSystem   *self,
                              const char       *id)
 {
-  return g_hash_table_lookup (self->priv->id_to_app, id);
+  ShellAppSystemPrivate *priv = self->priv;
+  ShellApp *app;
+  GDesktopAppInfo *info;
+
+  app = g_hash_table_lookup (priv->id_to_app, id);
+  if (app)
+    return app;
+
+  info = g_desktop_app_info_new (id);
+  if (!info)
+    return NULL;
+
+  app = _shell_app_new (info);
+  g_hash_table_insert (priv->id_to_app, (char *) id, app);
+  return app;
 }
 
 /**